/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package co.edu.usbcali.proyectofinal.dao;

import co.edu.usbcali.proyectofinal.modelo.TiposDocumentos;
import java.util.List;
import javax.annotation.Resource;
import org.hibernate.SessionFactory;
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Repository;

/**
 *
 * @author alejandro
 */
@Scope("singleton")
@Repository
public class TiposDocumentosDAO implements ITiposDocumentosDAO {

    @Resource
    private SessionFactory sessionFactory;

    @Override
    public void crearTipoDocumento(TiposDocumentos tiposDocumentos) throws Exception {
        sessionFactory.getCurrentSession().save(tiposDocumentos);
    }

    @Override
    public void modificarTipoDocumento(TiposDocumentos tiposDocumentos) throws Exception {
        sessionFactory.getCurrentSession().update(tiposDocumentos);
    }

    @Override
    public void borrarTipoDocumento(TiposDocumentos tiposDocumentos) throws Exception {
        sessionFactory.getCurrentSession().delete(tiposDocumentos);
    }

    @Override
    public TiposDocumentos consultarTipoDocumentoCodigo(long tdocCodigo) throws Exception {
        return (TiposDocumentos) sessionFactory.getCurrentSession().get(TiposDocumentos.class, tdocCodigo);
    }

    @Override
    public List<TiposDocumentos> consultarTodosLosTiposDocumentos() throws Exception {
        String hql = "SELECT tdoc FROM TiposDocumentos tdoc";
        return sessionFactory.getCurrentSession().createQuery(hql).list();
    }

}
